<template>
	<div>
		<div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<a :class="['mui-control-item',item.id == 0 ? 'mui-active' : '']" v-for="item in cates" :key="item.id" @click="getPhotoListByCateId(item.id)">
						{{ item.title }}
					</a>
				</div>
			</div>
		</div>

		<!--  -->
		<ul class="photo-list">
			<router-link :to="'/home/photoDetail/' + item.id" v-for="item in imgs" :key="item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h3 class="info-title">{{ item.title }}</h3>
					<p class="info-body">{{ item.zhaiyao }}</p>
				</div>
			</router-link>
		</ul>
	</div>
</template>

<script>
	import mui from '../../lib/mui/dist/js/mui.min.js'
	export default {
		data () {
			return {
				cates:[],
				imgs:[]
			}
		},
		mounted() {
	    //轮播图：获得slider插件对象
	    // scroll左右滚动
	    mui(".mui-scroll-wrapper").scroll({
	      // deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
	      scrollY: false, //是否竖向滚动
	      scrollX: true, //是否横向滚动
	      startX: 0, //初始化时滚动至x
	      startY: 0, //初始化时滚动至y
	      // indicators: true, //是否显示滚动条
	      deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
	      bounce: true //是否启用回弹
	    });
	  },
	  created() {
	  	this.getAllCategory ()
	  	this.getPhotoListByCateId(0);
	  },
	  methods: {
	  	getAllCategory () {
	  		this.$http.get('http://www.liulongbin.top:3005/api/getimgcategory').then( result => {
	  			if (result.body.status === 0) {
	  				result.body.message.unshift({ title: "全部", id: 0 })
	  				this.cates = result.body.message
	  				// console.log(result.body.message)
	  			}
	  		})
	  	},
	  	getPhotoListByCateId (cateId) {
	  		this.$http.get('http://www.liulongbin.top:3005/api/getimages/' + cateId).then(result => {
	  			if( result.body.status === 0 ) {
	  				this.imgs = result.body.message
	  				// console.log(this.imgs)
	  			}
	  		})
	  	}
	  }
	};
</script>

<style lang="less" scoped>
	.photo-list {
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom:0;
		li {
			background-color:#ccc;
			text-align: center;
			margin-bottom:10px;
			box-shadow:0 0 6px #999;
			position: relative;
			img{
				width:100%;
				vertical-align:middle;
			}
			image[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}
		}
	}
	.info {
		color: white;
		position: absolute;
		bottom: 0;
		left: 0;
		background: rgba(0, 0, 0, 0.4);
		text-align: left;
		.info-title {	
		font-size: 14px;
		}
		.info-body {
		font-size: 15px;
		color: white;
		}
	}
</style>